package cn.kevinking.common.util;

import lombok.experimental.UtilityClass;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.Objects;

/**
 * common utility class for datetime
 *
 * @author kevinking
 * @since 02 May 2025
 */
@UtilityClass
public class BfzDateTimeUtils {

	/**
	 * convert LocalDate to Date
	 * @param localDate target LocalDate object
	 * @return result Date object
	 */
	public Date fromLocalDate(LocalDate localDate) {
		localDate = Objects.nonNull(localDate) ? localDate : LocalDate.now();
		return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
	}

	/**
	 * convert LocalDateTime to Date
	 * @param localDateTime target LocalDateTime object
	 * @return result Date object
	 */
	public Date fromLocalDateTime(LocalDateTime localDateTime) {
		localDateTime = Objects.nonNull(localDateTime) ? localDateTime : LocalDateTime.now();
		return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
	}

}
